﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataAccess
{
    public class GVQuanLyMonHoc
    {
        //MonHoc.MaMH, MonHoc.TenMH,PhanCongGiangDay.HocKy,PhanCongGiangDay.NamHoc, MonHoc.SoTC, MonHoc.TCTH,MonHoc.TCLT, MonHoc.BatBuoc, MonHoc.MoTaMH
        private string _MaMh;
        public string MaMH
        {
            get { return _MaMh; }
            set { _MaMh = value; }
        }

        private string _TenMH;
        public string TenMH
        {
            get { return _TenMH; }
            set { _TenMH = value; }
        }

        private int _SoTC;
        public int SoTC
        {
            get { return _SoTC; }
            set { _SoTC = value; }
        }

        private int _TCLT;
        public int TCLT
        {
            get { return _TCLT; }
            set { _TCLT = value; }
        }

        private int _TCTH;
        public int TCTH
        {
            get { return _TCTH; }
            set { _TCTH = value; }
        }

        private bool _BatBuoc;
        public bool BatBuoc
        {
            get { return _BatBuoc; }
            set { _BatBuoc = value; }
        }

        private string _MoTaMH;
        public string MoTaMH
        {
            get { return _MoTaMH; }
            set { _MoTaMH = value; }
        }

        private string _HocKy;
        public string HocKy
        {
            get { return _HocKy; }
            set { _HocKy = value; }
        }

        private string _NamHoc;
        public string NamHoc
        {
            get { return _NamHoc; }
            set { _NamHoc = value; }
        }

        public GVQuanLyMonHoc() { }

        public GVQuanLyMonHoc(string mh, string ten, int tc, int lt, int th, bool bb, string hk, string nam,string mt)
        {
            MaMH = mh;
            TenMH = ten;
            SoTC = tc;
            TCLT = lt;
            TCTH = th;
            BatBuoc = bb;
            HocKy = hk;
            NamHoc = nam;
            MoTaMH = mt;
        }

        public GVQuanLyMonHoc(GVQuanLyMonHoc gvql)
        {
            MaMH = gvql.MaMH;
            TenMH = gvql.TenMH;
            SoTC = gvql.SoTC;
            TCLT = gvql.TCLT;
            TCTH = gvql.TCTH;
            BatBuoc = gvql.BatBuoc;
            HocKy = gvql.HocKy;
            NamHoc = gvql.NamHoc;
            MoTaMH = gvql.MoTaMH;
        }

        public static List<GVQuanLyMonHoc> All(string magv)
        {
            List<GVQuanLyMonHoc> list = new List<GVQuanLyMonHoc>();
            using (SqlConnection connec=MyConnection.MyConn())
            {
                SqlCommand cmd = MyCommand.Command("GiaoVien_LoadMonHoc", connec);
                cmd.Parameters.Add("@MaGv", SqlDbType.VarChar, 10).Value = magv;
                connec.Open();
                using (SqlDataReader reader=cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        GVQuanLyMonHoc gv = GetGV(reader);
                        list.Add(gv);
                    }
                }
                return list;
            }
        }
        private static GVQuanLyMonHoc GetGV(SqlDataReader reader)
        { 
            GVQuanLyMonHoc gv= new GVQuanLyMonHoc();
            gv.MaMH = reader["MaMH"].ToString();
            gv.TenMH = reader["TenMH"].ToString();
            gv.SoTC = CType.ToInt32(reader["SoTC"]);
            gv.HocKy = reader["HocKy"].ToString();
            gv.NamHoc = reader["NamHoc"].ToString();
            gv.TCLT = CType.ToInt32(reader["TCLT"]);
            gv.TCTH = CType.ToInt32(reader["TCTH"]);
            gv.BatBuoc = CType.ToBool(reader["BatBuoc"]);
            gv.MoTaMH = reader["MoTaMH"].ToString();
            return gv;

        }
    }
}
